<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>系统测试页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .test-item {
            margin: 10px 0;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        .success {
            background-color: #d4edda;
            border-color: #c3e6cb;
            color: #155724;
        }
        .error {
            background-color: #f8d7da;
            border-color: #f5c6cb;
            color: #721c24;
        }
        .loading {
            background-color: #fff3cd;
            border-color: #ffeaa7;
            color: #856404;
        }
        button {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 8px 16px;
            border-radius: 4px;
            cursor: pointer;
            margin: 5px;
        }
        button:hover {
            background-color: #0056b3;
        }
        #results {
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Tete1 Git同步系统 - 测试页面</h1>
        <p>这是一个简单的测试页面，用于验证系统是否正常工作。</p>

        <div class="test-item">
            <h3>系统信息</h3>
            <p>当前时间: <span id="current-time"></span></p>
            <p>用户代理: <span id="user-agent"></span></p>
            <p>访问地址: <span id="current-url"></span></p>
        </div>

        <div class="test-item">
            <h3>API测试</h3>
            <button onclick="testAPI()">测试API连接</button>
            <button onclick="testSystemAPI()">测试系统API</button>
            <button onclick="testTasksAPI()">测试任务API</button>
        </div>

        <div id="results"></div>
    </div>

    <script>
        // 显示当前时间
        function updateTime() {
            document.getElementById('current-time').textContent = new Date().toLocaleString();
        }
        updateTime();
        setInterval(updateTime, 1000);

        // 显示用户代理
        document.getElementById('user-agent').textContent = navigator.userAgent;
        document.getElementById('current-url').textContent = window.location.href;

        // 测试API函数
        async function testAPI() {
            const resultsDiv = document.getElementById('results');
            const testDiv = document.createElement('div');
            testDiv.className = 'test-item loading';
            testDiv.innerHTML = '<h4>API连接测试</h4><p>正在测试...</p>';
            resultsDiv.appendChild(testDiv);

            try {
                const response = await fetch('/api/v1/system/info');
                const data = await response.json();

                if (response.ok) {
                    testDiv.className = 'test-item success';
                    testDiv.innerHTML = `
                        <h4>API连接测试 - 成功</h4>
                        <p>状态码: ${response.status}</p>
                        <p>系统名称: ${data.name}</p>
                        <p>系统版本: ${data.version}</p>
                        <p>响应时间: ${new Date().toLocaleString()}</p>
                    `;
                } else {
                    throw new Error(`HTTP ${response.status}: ${response.statusText}`);
                }
            } catch (error) {
                testDiv.className = 'test-item error';
                testDiv.innerHTML = `
                    <h4>API连接测试 - 失败</h4>
                    <p>错误信息: ${error.message}</p>
                    <p>时间: ${new Date().toLocaleString()}</p>
                `;
            }
        }

        async function testSystemAPI() {
            const resultsDiv = document.getElementById('results');
            const testDiv = document.createElement('div');
            testDiv.className = 'test-item loading';
            testDiv.innerHTML = '<h4>系统API测试</h4><p>正在测试...</p>';
            resultsDiv.appendChild(testDiv);

            try {
                const response = await fetch('/api/v1/system/info');
                const data = await response.json();

                if (response.ok) {
                    testDiv.className = 'test-item success';
                    testDiv.innerHTML = `
                        <h4>系统API测试 - 成功</h4>
                        <p>系统名称: ${data.name}</p>
                        <p>系统版本: ${data.version}</p>
                        <p>系统描述: ${data.description}</p>
                        <p>功能特性: ${data.features ? data.features.join(', ') : '无'}</p>
                    `;
                } else {
                    throw new Error(`HTTP ${response.status}: ${response.statusText}`);
                }
            } catch (error) {
                testDiv.className = 'test-item error';
                testDiv.innerHTML = `
                    <h4>系统API测试 - 失败</h4>
                    <p>错误信息: ${error.message}</p>
                `;
            }
        }

        async function testTasksAPI() {
            const resultsDiv = document.getElementById('results');
            const testDiv = document.createElement('div');
            testDiv.className = 'test-item loading';
            testDiv.innerHTML = '<h4>任务API测试</h4><p>正在测试...</p>';
            resultsDiv.appendChild(testDiv);

            try {
                const response = await fetch('/api/v1/tasks/');
                const data = await response.json();

                if (response.ok) {
                    testDiv.className = 'test-item success';
                    testDiv.innerHTML = `
                        <h4>任务API测试 - 成功</h4>
                        <p>总任务数: ${data.total}</p>
                        <p>当前页: ${data.page}</p>
                        <p>每页大小: ${data.size}</p>
                        <p>总页数: ${data.pages}</p>
                    `;
                } else {
                    throw new Error(`HTTP ${response.status}: ${response.statusText}`);
                }
            } catch (error) {
                testDiv.className = 'test-item error';
                testDiv.innerHTML = `
                    <h4>任务API测试 - 失败</h4>
                    <p>错误信息: ${error.message}</p>
                `;
            }
        }

        // 页面加载时自动测试
        window.addEventListener('load', function() {
            setTimeout(testAPI, 1000);
            setTimeout(testSystemAPI, 2000);
            setTimeout(testTasksAPI, 3000);
        });
    </script>
</body>
</html>